<?php
/*function isPrice($value){
	$array=split(".",$value);echo $value;print_r($array);
	if($value==''){
		echo 'a';return 0;
	}
	if($array[1]==''){
		echo 'b';return digits($array[0]);
	}
	if($array[2]){
		echo 'c';return 0;
	}
	if(digits($array[0])&&digits($array[1])){
		echo 'd';return 1;
	} else {
		echo 'e';return 0;
	}
}*/
function minlength ($length, $param) {
	return $length >= $param;
}

// http://docs.jquery.com/Plugins/Validation/Methods/maxlength
function maxlength ($length, $param) {
	return $length <= $param;
}

// http://docs.jquery.com/Plugins/Validation/Methods/rangelength
function rangelength ($length, $param0,$param1) {
	if( ( ($length >= $param0 ) && ($length <= $param1) )){
		return 1;
	} else {
		return 0;
	}
}
function checkPhone($str){
	$phone2 = "/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/";
	if (preg_match($phone2,$str)) {
   		return 1;
 	} else {
 		return 0;
 	}
}
function isPhone($phone){
	$regPhone="/^[0-9]{10,15}$/";
	if(preg_match($regPhone,$phone)){
		return 1;
	}else{
		return 0;
	}
}
// http://docs.jquery.com/Plugins/Validation/Methods/min
function minValue ( $value, $param ) {
	if( $value >= $param){
		return 1;
	} else {
		return 0;
	}
}

// http://docs.jquery.com/Plugins/Validation/Methods/max
function maxValue( $value, $param ) {
	if( $value <= $param){
		return 1;
	} else {
		return 0;
	}
}

// http://docs.jquery.com/Plugins/Validation/Methods/range
function rangeString ( $string, $param0, $param1 ) {
	$value=strlen($string);
	if ( $value >= $param0 && $value <= $param1 ){
		return 1;
	} else {
		return 0;
	}
}

// http://docs.jquery.com/Plugins/Validation/Methods/dateISO
function dateISO ($value) {
	return preg_match("/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/",$value);
}

// http://docs.jquery.com/Plugins/Validation/Methods/dateDE
function dateDE ($value) {
	return preg_match("/^\d\d?\.\d\d?\.\d\d\d?\d?$/",$value);
}
	
// http://docs.jquery.com/Plugins/Validation/Methods/number
// 12,123,123.123 || 12123123.123
function isNumber ($value) {
	return preg_match("/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/",$value);
}
/*Prime  number*/
function priNumber ($value) {
	return preg_match("/^[0-9]+$/",$value);
}

// http://docs.jquery.com/Plugins/Validation/Methods/numberDE
// 12.123.123,123 || 12.123.123,123
function numberDE ($value) {
	return preg_match("/^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/",$value);
}
		
// http://docs.jquery.com/Plugins/Validation/Methods/digits
function digits ($value) {
	return  preg_match("/^\d+$/",$value);
}
		
// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
function equalTo ($value, $param) {
	return $value == $param;
}
function dateVN($value){
	return preg_match("/^\d{1,2}[\/-]\d{1,2}[\/-]\d{4}$/",$value)||preg_match("/^\d{4}-\d{2}-\d{2}$/",$value);
}
function isDate($string,$fomat='d/m/y'){
	if(!dateVN($string)){
		return 0;
	}
	$f=array();$f=split('[/.-]',$fomat);
	$str=array(); $str=split('[/.-]',$string);
	for ($i=0;$i<=2;$i++){
		switch($f[$i]){
			case 'm';	$m=$str[$i]; break;
			case 'd';	$d=$str[$i]; break;
			case 'y';	$y=$str[$i]; break;
		}
	}
	//return $m.$d.$y;
	if(checkdate($m,$d,$y)){
		return 1;
	}else {
		return 0;
	}
}		
function isTime($value){
	return preg_match("/^(([01]{1}[0-9]{1})|([2]{1}[0-3]{1}))\:([0-5]{1}[0-9]{1})$/",$value);
}
// http://docs.jquery.com/Plugins/Validation/Methods/email
function isEmail ($value) {
	// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
	return preg_match("/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)((|\-)*)@([A-Za-z0-9_]+)(([\.\-]?[a-zA-Z0-9_]+)*)\.([A-Za-z]{2,})$/i",$value);
}
	
// http://docs.jquery.com/Plugins/Validation/Methods/url
function isUrl ($value) {
	// contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
	return preg_match("/^(mailto\:|(news|(ht|f)tp(s?))\://)(([^[:space:]]+)|([^[:space:]]+)( #([^#]+)#)?)$/i",$value);
}
?>